package com.xiaodu.acer.phoneplay;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import io.reactivex.functions.Consumer;
import zlc.season.rxdownload2.RxDownload;
import zlc.season.rxdownload2.entity.DownloadEvent;

/**
 * @author 小杜
 *         邮箱:m15701207383@163.com
 * @version V1.0
 * @Description: ${TODO}(用一句话描述该文件做什么)
 * @date 2018/1/22 11:13
 */

public class DownTestActivity extends Activity {
    private static final String api = "http://shouji.360tpcdn.com/170918/a01da193400dd5ffd42811db28effd53/com.tencent.mobileqq_730.apk";
    private Button mStartButton;
    private Button mPauseButton;
    private RxDownload mRxDownload;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        mStartButton = findViewById(R.id.start);
        mPauseButton = findViewById(R.id.pause);
        mRxDownload = new RxDownload(this);
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                download();
            }
        });

        mPauseButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pause();
            }
        });

    }

    private void download() {
        mRxDownload.serviceDownload(api)
                .subscribe();
        mRxDownload.receiveDownloadStatus(api)
                .subscribe(new Consumer<DownloadEvent>() {
                    @Override
                    public void accept(DownloadEvent event) throws Exception {
                        System.out.println(event.getDownloadStatus());
                    }
                });
    }


    private void pause() {
        mRxDownload.pauseServiceDownload(api).subscribe();
    }
}
